package gazzera.utils;

import java.io.PrintWriter;
import java.io.StringWriter;
import java.util.*;

public class Str
{

    public static boolean isEmpty(String s)
    {
	return s == null || s.equals("");
    }

    public static String join(Collection<?> c, String separator)
    {
	StringBuilder b = new StringBuilder();
	for (Object object : c)
	{
	    if (b.length() > 0)
	    {
		b.append(separator);
	    }
	    b.append(object);
	}
	return b.toString();
    }
    
    public static String asciiOnly(String inp)
    {
    	return inp.replaceAll("^\\p{ASCII}", "");	
    }
    
    public static String strip(String inp)
    {
    	return inp.replaceAll("\\W", "");	
    }
    public static String getStackTrace(Throwable t)
    {
        StringWriter sw = new StringWriter();
        PrintWriter pw = new PrintWriter(sw, true);
        t.printStackTrace(pw);
        pw.flush();
        sw.flush();
        return sw.toString();
    }
}
